gene<-read.table("merge_expr_filtered",sep="\t",head =T)
anno<-read.table("file_final_ucscnew",sep="\t")
rownames(anno)<-as.vector(anno[,1])
gene1<-merge(anno,gene,by="row.names",all.x=F)
i<-1
samplesize<-20
num<-as.integer((length(gene1[1,])-4)/samplesize)
#num<-0
geno<-read.table("combined_GBM_normal_plink_final_filetered_het_minhomo_10.tped",sep=" ")
predgene<-matrix(nrow=nrow(gene1), ncol=ncol(gene1)-4)
while(i<nrow(gene1)+1)
{
	if(gene1[i,3] == "+"){l1 = gene1[i,4]-30000;l2=gene1[i,4]+20000}else{l1 = gene1[i,4]-20000;l2=gene1[i,4]+30000}
	index<-which(geno[,4]>=l1 & geno[,4]<l2)
	geno1<-geno[index,]
	eqtlgene<-as.matrix(gene1[i,5:ncol(gene1)])	
	eqtlgeno<-as.matrix(geno1[8:ncol(geno1)])
	#script attached
	s<-0
	s2<-1
	s1<-samplesize
	#predgene<-c()
	#colnames(predgene)<-colnames(gene1[i,1])
	while(s<=num)
	{
        	if(s1 > length(gene1[1,])-4)
        	{
           		s1<- length(gene1[1,])-4
        	}
        	sub<-seq(s2,s1,1)
        	main1<-seq(1,s2,1)
        	if(s1 == length(gene1[1,])-4)
        	{
                	main2<-c()
        	}
        	else
        	{
                	main2<-seq(s1+1,length(gene1[1,])-4,1)
        	}
        	main<-c(main1[1:length(main1)-1],main2)
		
		#sub script start
		geneeqtl<-t(as.matrix(eqtlgene[,main]))
		genomaineqtl<-eqtlgeno[,main]
		genosubeqtl<-eqtlgeno[,sub]
		d1 <- data.frame(geneeqtl[1,],genomaineqtl[1,])
        	colnames(d1)<-c("gene","genotype")
		glm1 <- glm(gene ~ genotype, data=d1,family=gaussian(link="log"))
		vec1<-as.data.frame(as.vector(genosubeqtl[1,]))
		colnames(vec1)<-c("genotype")
		pred <- predict(glm1, data.frame(cbind(genotype=vec1)), type="response")	
		t<-1
		while(t<length(sub)+1)
		{
			predgene[i,sub[t]]<-pred[t]
			#print(pred[i,])
			t<-t+1
		}		
		#sub script end

       	 	s<-s+1
		s1<-s1+samplesize
        	s2<-s2+samplesize
	}
	#print(predgene[1,])
	i<-i+1
}

